<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增产品属性')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-sellPartsAttribute-add">
            <input id="partsId" name="partsId" th:value="${partsId}" type="hidden">
            <input id="attributeLogo" name="attributeLogo" class="form-control" type="hidden" required>
            <div class="form-group">    
                <label class="col-sm-3 control-label">属性名称：</label>
                <div class="col-sm-8">
                    <input name="attributeName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">属性logo：</label>
                <div class="col-sm-8">
                    <p class="user-info-head" onclick="avatarAttribute()"><img id="attributeLogoShow" class="img-thumbnail img-lg" ></p>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">统一批发价：</label>
                <div class="col-sm-8">
                    <input name="attributeWholesalePrice" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">统一零售价：</label>
                <div class="col-sm-8">
                    <input name="attributeRetailPrice" class="form-control" type="text">
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label is-required">排序：</label>
                <div class="col-sm-8">
                    <input name="attributeSort" class="form-control" type="text" required>
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">属性备注：</label>
                <div class="col-sm-8">
                    <textarea name="attributeRemarks" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否上架：</label>
                <div class="col-sm-8">
                    <select name="isShow" class="form-control m-b" th:with="type=${@dict.getType('zsyh_yesno')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">运费：</label>
                <div class="col-sm-8">
                    <input name="attributeShippingFee" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">偏远地区的运费：</label>
                <div class="col-sm-8">
                    <input name="attributeShippingFeeremote" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/sellPartsAttribute"
        $("#form-sellPartsAttribute-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-sellPartsAttribute-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/uploadOSS',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })

        function avatarAttribute() {
            var url = ctx + 'zsyh/sellPartsAttribute/avatarAttribute?attributeLogo='+$("#attributeLogo").val();
            layer.open({
                type: 2,
                area: [$(window).width()/2 + 'px', $(window).height() + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "上传规格图片",
                content: url,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    debugger;
                    var iframeWin = layero.find('iframe')[0];
                    var imageUrl = layero.find('iframe')[0].contentWindow.$("#imageUrl").val();
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

    </script>
</body>
</html>